/**
 * Copyright (c) suzuki ryoutoku
 * See this code regarding the Apache License Version 2.0
 * @author suzuki ryoutoku
 */

//=============================================================================
//	Protected multiple include file
//=============================================================================

#ifndef GLOBALPARAMETER_H
#define GLOBALPARAMETER_H

//=============================================================================
//	Pre processor
//=============================================================================
#include <gtk/gtk.h>
#include <iostream>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <gdk/gdkkeysyms.h>
#include <unistd.h>
#include <sys/time.h>
#include <pthread.h>
#include "include/library.h"
using namespace library::graphics;
using namespace library::log;

//=============================================================================
//	Alias 
//=============================================================================
#define APPLICATION_NAME "StripExperiment"
#define AUTHOR			 "suzuki"
#define MAIN_WINDOW_WIDTH 550
#define MAIN_WINDOW_HEIGHT 400
#define NOTEBOOK_WIDTH 150
#define NOTEBOOK_HEIGHT 350
#define HIERARCHY_VIEW_TAB_LABEL "hierarchy"
#define ATTRIBUTE_VIEW_TAB_LABEL "attribute"
#define DRAW_AREA_WIDTH 300
#define DRAW_AREA_HEIGHT 300
#define LOG_FILENAME "stripexperiment.log"

#define MENU_FILE "File"
#define OPEN_3DSFILE_MENU "Open 3ds file"
#define OPEN_VDFFILE_MENU "Open vdf file"
#define OPEN_PCMFILE_MENU "Open pcm file"
#define SUB_MENU_OUTPUT_PCMFILE "Output pcm file"
#define SUB_MENU_OUTPUT_VDFFILE "Output vdf file"
#define CAPTURE_DRAWWINDOW  "Capture draw window"

#define MENU_DISPLAY "Display"
#define SUB_MENU_TOGGLE_FPS	"Toggle FPS"
#define SUB_MENU_SCALING "Scaling"
#define SUB_MENU_RESET_COORDINATE "Reset coordinate"
#define SUB_MENU_SETTING_LIGHT_PARAMETER "Setting Light parameter"

#define MENU_SELECTION "Selection"
#define SUB_MENU_NONE "None"
#define SUB_MENU_VERTEX "Vertex"
#define SUB_MENU_POLYGON "Polygon"

#define MENU_EDIT "Edit"
#define SUB_MENU_CREATE_TRIANGLESTRIP "Create triangle strip"


#define MENU_HELP "Help"
#define SUB_MENU_ABOUT_STRIPEXPERIMENT "About Stripexperiment"

#define APPLICATION_VERSION "0.2.0.0"
#define LICENSE "Apache License Version 2.0"
#define WEBSITE "http://d.hatena.ne.jp/malibu-bulldog/"
#define COPYRIGHT "Copyright (c) 2007-2008 suzuki"

//=============================================================================
//	Define class
//=============================================================================
/**
 * Global parameter manager.
 * \note
 * All global parameter is controled by this class.
 * This class instance is unique in application.
 * Mechanism of this class refer to singleton pattern.
 *
 * All members are allowed you to get and set by inline method.
 *
 * @author suzuki ryoutoku
 * @date 2007-12-17
 * @version 1.0
 */
class GlobalParameter
{
  // closed member
private:
  GtkWidget* 	 m_main_window;//!< Main window of this application
  GtkWidget* 		 _drawarea;/**< 
								  Drawing window's parent for 3d model by 
								  opengl.
								  User can not see this window.
								  User can see this windows's child window.
							   */
  GtkTreeView* m_hierarchyview;/**< 
								  This member is Gtk's tree view window.
								  Place of this window is left in Main window.
								*/
  GtkTreeView* m_attributeview;
  GtkWidget*	 m_symboltable;//!< This window is to show symbol table.
  RenderingManager*		  m_rm;//!< This application's rendering manager.
  Model* 			   m_model;/**<
								  This application has only pointer of 
								  model data 
							   */
  DrawString m_shapeinformation;//!< To display face & vertex sum information
  DrawString 			 m_fps;//!< To display fps information 
  Sprite*		  m_background;//!< To draw background image
  gdouble			m_before_x;//!< Temporary data to be stored Mouse's x
  gdouble 			m_before_y;//!< Temporary data to be stored Mouse's y
  gdouble			m_before_z;//!< Temporary data to be stored Mouse's scrol
  GtkWidget*	   m_line_menu;//!< line menu widget
  char	 _data_directory[1024];//!< This Application's current directory
  char	m_home_directory[1024];//!< This Application's home directory
  double				 m_div;//!< 
  unsigned int		m_keystate;//!< now user input key.
  GtkProgressBar* 	m_progress;
  GtkWidget* m_progress_dialog;
  unsigned int m_strip_counter;
  SelectStarting _strip_start_select;
  GraphicalObjectType _selection;
  GtkWidget*   _check_selectpoly;
  GtkWidget*   _check_selectvert;

  // opened method
public:
  GlobalParameter();
  ~GlobalParameter();

  void resetMouseCoordinate(void);
  void substituteMouseCoordinate(gdouble ix = -1,
								 gdouble iy = -1,
								 gdouble iz = -1);
  void releaseModelData(void);

  bool readTextureFile(Reader* reader);

  bool initializeaLogManager(void);
  bool createBackground(void);
  bool createDefaultData(void);
  bool createDrawingString(void);
  bool initializeModelData(void);
  bool initializeTreeView(void);

  bool createHierarchyViewWindow(void);
  bool createAttributeViewWindow(void);
  bool initializeAttributeView(GtkTreeStore* store, bool flag);
  bool createNotebook(GtkWidget* hbox);
  bool createDrawArea(GtkWidget* hbox);
  

  // inline setter & getter
public:
  GtkWidget* getM_main_window(){return this->m_main_window;}
  void setM_main_window(GtkWidget* arg){this->m_main_window = arg;}

  GtkWidget* get_drawarea(void){return this->_drawarea;}
  //void setM_parent_drawarea(GtkWidget* arg){m_parent_drawarea = arg;}

  GtkTreeView* getM_hierarchyview(){return m_hierarchyview;}
  void setM_hierarchyview(GtkTreeView* arg){this->m_hierarchyview = arg;}

  GtkTreeView* getM_attributeview(){return m_attributeview;}
  void setM_attributeview(GtkTreeView* arg){this->m_attributeview = arg;}


  RenderingManager* getM_rm(){return m_rm;}
  void setM_rm(RenderingManager* arg){this->m_rm = arg;}

  Model* getM_model(void){return m_model;}
  void setM_model(Model* arg){m_model = arg;}

  gdouble getM_before_x(void){return this->m_before_x;}
  gdouble getM_before_y(void){return this->m_before_y;}
  gdouble getM_before_z(void){return this->m_before_z;}

  void setM_before_x(gdouble arg){this->m_before_x=arg;}
  void setM_before_y(gdouble arg){this->m_before_y=arg;}
  void setM_before_z(gdouble arg){this->m_before_z=arg;}

  DrawString* getM_shapeinformation(void){return &(this->m_shapeinformation);}
  DrawString* getM_fps(void){return &(this->m_fps);}

  GtkWidget* getM_line_menu(void){return this->m_line_menu;}
  void setM_line_menu(GtkWidget* arg){this->m_line_menu=arg;}

  char* get_data_directory(){return _data_directory;}
  void set_data_directory(char* arg){strcpy(_data_directory,arg);}

  char* getM_home_directory(){return this->m_home_directory;}
  double getM_div(void){return this->m_div;}
  void setM_div(double arg){this->m_div=arg;}

  unsigned int getM_keystate(void){return this->m_keystate;}
  void setM_keystate(unsigned int arg){this->m_keystate=arg;}

  GtkProgressBar* getM_progress(void){return this->m_progress;}
  void setM_progress(GtkProgressBar* arg){this->m_progress=arg;}

  GtkWidget* getM_progress_dialog(void){return this->m_progress_dialog;}
  void setM_progress_dialog(GtkWidget* arg){this->m_progress_dialog=arg;}
  
  unsigned int getM_strip_counter(void){return this->m_strip_counter;}
  void setM_strip_counter(unsigned int arg){this->m_strip_counter=arg;}

  Sprite* getM_background(void){return this->m_background;}
  void setM_background(Sprite* arg){this->m_background=arg;}

  void set_strip_start_select(SelectStarting arg){_strip_start_select = arg;}
  SelectStarting get_strip_start_select(void){return _strip_start_select;}

  void set_selection(GraphicalObjectType arg){_selection=arg;}
  GraphicalObjectType get_selection(void){return _selection;}

  GtkWidget* get_check_selectpoly(){return _check_selectpoly;}
  GtkWidget* get_check_selectvert(){return _check_selectvert;}
  void set_check_selectpoly(GtkWidget* arg){_check_selectpoly=arg;}
  void set_check_selectvert(GtkWidget* arg){_check_selectvert=arg;}

  // closed class member
private:
  static GlobalParameter instance;

  // opened class method
public:
  static GlobalParameter* getInstance();
  static bool CreateBitmapFromJpgfile(BITMAPINFO*,
									  unsigned int** , 
									  const char* );

  static gint OnDraw(GtkWidget*, GdkEventExpose*, gpointer);
  static void OnRealize(GtkWidget *widget, gpointer data);
};


//=============================================================================
//	Protected multiple include file
//=============================================================================
#endif
